/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.yxw.yxnet_cd_center.customer_service.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.yxw.yxnet_cd_center.customer_service.entity.YxcscClientFiledServiceEntity;
import com.yxw.yxnet_cd_center.customer_service.service.IMqttObjectService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
//import com.yxw.yxnet_cd_center.common.constant.MqttPrefixConstant;
import com.yxw.yxnet_cd_center.customer_service.vo.MemberVo;
import com.yxw.yxnet_cd_center.customer_service.vo.MqttSystemEventContenVO;
import com.yxw.yxnet_cd_center.customer_service.vo.MqttSystemEventVO;
import org.springframework.stereotype.Service;



/**
 *
 * @author Administrator
 */
@Service
public class MqttObjectServiceImpl implements IMqttObjectService{
    /*** 
    * 系统通知_客服
    * @param oYxcscClientFiledServiceEntity
    * @param notifiType 通知类别
    * @param customerId 客服Id
    * @return BaseResult
    **/
    @Override
    public JSONObject MqttSystemNotification(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity,String notificationType,String customerId,String msg)
    {
        /*
        MqttObjectSystemVO oMqttObjectSystemVO = new MqttObjectSystemVO();
        oMqttObjectSystemVO.setChannelCode(oYxcscClientFiledServiceEntity.getChannelCode());
        oMqttObjectSystemVO.setPortCode(oYxcscClientFiledServiceEntity.getPortCode());
        oMqttObjectSystemVO.setShopId(oYxcscClientFiledServiceEntity.getShopId());
        oMqttObjectSystemVO.setRecv(customerId.toString());
        oMqttObjectSystemVO.setMsgType("notification");
        oMqttObjectSystemVO.setNotificationType(notificationType);
        oMqttObjectSystemVO.setContentType("text");
        oMqttObjectSystemVO.setContent(msg);
        JSONObject oJSONObject = (JSONObject)JSON.toJSON(oMqttObjectSystemVO);
        */
        JSONObject oJSONObject = new JSONObject();
        oJSONObject.put("channelCode", oYxcscClientFiledServiceEntity.getChannelCode());
        oJSONObject.put("portCode", oYxcscClientFiledServiceEntity.getChannelCode());
        oJSONObject.put("shopId", oYxcscClientFiledServiceEntity.getShopId());
        oJSONObject.put("recv",customerId);
        oJSONObject.put("flockiD",oYxcscClientFiledServiceEntity.getFlockId());
        oJSONObject.put("msgType","notification");
        oJSONObject.put("notificationType",notificationType);
        oJSONObject.put("contentTyp","text");
        oJSONObject.put("content",msg);
        return oJSONObject;
    }
     /*** 
    * 系统事件_客服
    * @param oYxcscClientFiledServiceEntity
    * @param eventType 事件类别
    * @param customerId 客服Id
    * @param msg 显示的消息
    * @return BaseResult
    **/
    @Override
    public JSONObject MqttSystemEvent(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity,String eventType,MemberVo oRecvMemberVo,String msg)
    {
        
        MqttSystemEventVO oMqttInforSystemVO = new MqttSystemEventVO();
        oMqttInforSystemVO.setChannelCode(oYxcscClientFiledServiceEntity.getChannelCode());
        oMqttInforSystemVO.setPortCode(oYxcscClientFiledServiceEntity.getPortCode());
        oMqttInforSystemVO.setShopId(oYxcscClientFiledServiceEntity.getShopId());
        oMqttInforSystemVO.setSessionId(oYxcscClientFiledServiceEntity.getId());
        oMqttInforSystemVO.setRecv(oRecvMemberVo.getId().toString());
        oMqttInforSystemVO.setFlockId(oRecvMemberVo.getFlockId());
        oMqttInforSystemVO.setMsgType("sys");                
        oMqttInforSystemVO.setContentType("json");
        oMqttInforSystemVO.setSystemEvnetType(eventType);
        MqttSystemEventContenVO oMqttSysContenVO = new MqttSystemEventContenVO();
        BeanUtil.copyProperties(oYxcscClientFiledServiceEntity, oMqttSysContenVO);
        oMqttSysContenVO.setClientId(oYxcscClientFiledServiceEntity.getClientId());
        oMqttSysContenVO.setClientName(oYxcscClientFiledServiceEntity.getClientName());
        oMqttSysContenVO.setClientAvatar(oYxcscClientFiledServiceEntity.getClientAvatar());
        oMqttSysContenVO.setShowMessage(msg);
        oMqttInforSystemVO.setContent(oMqttSysContenVO);
        JSONObject oJSONObject = (JSONObject)JSON.toJSON(oMqttInforSystemVO);
        return oJSONObject;
        /*
        JSONObject oJSONObject = new JSONObject();
        oJSONObject.put("channelCode", oYxcscClientFiledServiceEntity.getChannelCode());
        oJSONObject.put("portCode", oYxcscClientFiledServiceEntity.getChannelCode());
        oJSONObject.put("shopId", oYxcscClientFiledServiceEntity.getShopId());
        oJSONObject.put("shopId", oYxcscClientFiledServiceEntity.getShopId());
        return oJSONObject;
        */
    }
    /*** 
    * 客户发送聊天记录给客服
    * @param sendTalkMsgByClient
    * @return BaseResult
    **/
    @Override
    public JSONObject sendTalkMsgByClient(String channelCode,String portCode,String shopId,String Recv,String notificationType,String msg){
        /*
        oMqttObjectSystemVO = new MqttObjectSystemVO();
        oMqttObjectSystemVO.setChannelCode(oYxcscClientFiledServiceEntity.getChannelCode());
        oMqttObjectSystemVO.setPortCode(oYxcscClientFiledServiceEntity.getPortCode());
        oMqttObjectSystemVO.setShopId(oYxcscClientFiledServiceEntity.getShopId());
        oMqttObjectSystemVO.setRecv(oYxcscClientFiledServiceEntity.getUserId().toString());
        oMqttObjectSystemVO.setMsgType("notification");                
        oMqttObjectSystemVO.setContentType("sound");
        oMqttObjectSystemVO.setContent(msg);        
        oJSONObject = (JSONObject)JSON.toJSON(oMqttObjectSystemVO);
        */
        JSONObject oJSONObject = new JSONObject();
        return oJSONObject;
    }
    /*** 
    * 系统事件_客服
    * @param oYxcscClientFiledServiceEntity
    * @param eventType 事件类别
    * @param customerId 客服Id
    * @param msg 显示的消息
    * @return BaseResult
    **/   
    public JSONObject MqttSystemEventToClient(YxcscClientFiledServiceEntity oYxcscClientFiledServiceEntity,String eventType,String msg)
    {  
        JSONObject oJSONObject = new JSONObject();
        oJSONObject.put("msgType", "sys");
        oJSONObject.put("content", "inviteClientScore");
        oJSONObject.put("contentType", "text");
        oJSONObject.put("sessionId", oYxcscClientFiledServiceEntity.getId());
        JSONObject oSenderJSONObject = new JSONObject();
        oSenderJSONObject.put("userId", "system");
        oJSONObject.put("send", oSenderJSONObject);
        oJSONObject.put("recv", oYxcscClientFiledServiceEntity.getClientId());
        oJSONObject.put("sendTime",System.currentTimeMillis());
        return oJSONObject;
    }    
}
